import javax.swing.*;
import java.awt.*;

public class DrawColor {
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable(){
            public void run(){
                JFrame frame = new JFrame();
                frame.setTitle("2D图形颜色填充");
                //frame.setBackground(Color.black);

                MyComponent mp = new MyComponent();

                JPanel panel = new JPanel();
                panel.setSize(100,100);
                panel.setBackground(Color.cyan);

                mp.addMouseListener(new MouseInputAdapter());
                mp.addMouseMotionListener(new MouseInputAdapter());

                //mp.setOpaque(true);//将component设置为不透明
                mp.setBackground(Color.blue);
                frame.add(mp);
                frame.setLayout(null);

                frame.setSize(400,400); //设置窗口大小
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
            }
        });
    }
}